<?php


namespace app\api\controller\setting;

use app\common\controller\BaseController;
use app\common\service\distribution\MemberDistributionService;
use app\common\service\member\MemberAccountService;
use app\common\service\member\MemberService;
use app\common\service\member\SettingService as MemberSetting;
use app\common\service\content\SettingService as ContentSetting;
use app\common\service\file\SettingService as FileSetting;
use app\common\service\order\ShopOrderService;
use app\common\service\setting\SettingService;
use app\common\service\system\SettingService as SystemSettingService;
use app\common\service\setting\LinkService;
use app\common\service\webscoket\SwooleTaskService;
use hg\apidoc\annotation as Apidoc;

/**
 * @Apidoc\Title("设置")
 * @Apidoc\Group("setting")
 * @Apidoc\Sort("100")
 */
class Setting extends BaseController
{
    /**
     * @Apidoc\Title("设置信息")
     * @Apidoc\Returned("member", type="object", desc="会员设置", children={
     *   @Apidoc\Returned(ref="app\common\model\member\SettingModel", field="is_captcha_register,is_captcha_login,is_register,is_login,is_captcha_register,is_captcha_login,is_phone_register,is_phone_login,is_email_register,is_email_login"),
     *   @Apidoc\Returned(ref="app\common\service\member\SettingService\info", field="default_avatar_url,token_type,token_name")
     * })
     * @Apidoc\Returned("content", type="object", desc="内容设置", children={
     *   @Apidoc\Returned(ref="app\common\model\content\SettingModel", withoutField="create_uid,update_uid,create_time,update_time"),
     *   @Apidoc\Returned(ref="app\common\service\content\SettingService\info")
     * })
     * @Apidoc\Returned("file", type="object", desc="文件设置", children={
     *   @Apidoc\Returned(ref="app\common\model\file\SettingModel", field="is_upload_api,storage,image_ext,image_size,video_ext,video_size,audio_ext,audio_size,word_ext,word_size,other_ext,other_size,is_api_file,api_file_types,api_file_group_ids,api_file_tag_ids"),
     *   @Apidoc\Returned(ref="app\common\service\file\SettingService\info", field="accept_ext")
     * })
     * @Apidoc\Returned("setting", type="object", desc="设置管理", children={
     *   @Apidoc\Returned(ref="app\common\model\setting\SettingModel"),
     *   @Apidoc\Returned(ref="app\common\service\setting\SettingService\info")
     * })
     * @Apidoc\Returned("link", type="array", desc="友链列表", children={
     *   @Apidoc\Returned(ref="app\common\model\setting\LinkModel", field="link_id,image_id,name,name_color,url,desc"),
     *   @Apidoc\Returned(ref="app\common\model\setting\LinkModel\getImageUrlAttr", field="image_url")
     * })
     * @Apidoc\NotHeaders()
     * @Apidoc\NotQuerys()
     * @Apidoc\NotParams()
     */
    public function setting()
    {
        // 会员设置
        $data['member']  = MemberSetting::info('is_captcha_register,is_captcha_login,is_register,is_login,is_captcha_register,is_captcha_login,is_phone_register,is_phone_login,is_email_register,is_email_login,default_avatar_url,token_type,token_name,logo_id,logo_url,real_name_auth,is_upload_idcard_front,is_upload_idcard_opposite,is_upload_idcard_hand,is_idcard_edit,order_mode,order_force_hand,order_effective_time,distribution_mode');
        //是否显示抢单菜单
        $data['is_task']  =0;
        $member_id = member_id(false);
        if($member_id>0){
            $member_data = MemberService::getUserInfo($member_id, true,'is_task');
            if($member_data['is_task'] == 1){
                $data['is_task']  =1;
            }
        }
        //查询分销等级佣金
        $distribution_list = [];
        $data['distribution_rebate_type'] =1;
        $distribution = MemberDistributionService::list([
            ['is_default','=',1],
            ['is_disable','=',0],
            ['is_delete','=',0],
        ], 0, 0, $this->order(),'rebate_type,rebate_one,rebate_two,rebate_three');
        if(count($distribution)>0){
            $distribution = $distribution[0];
            $suffix = "";
            if($distribution['rebate_type']==2){
                $suffix ="%";
                $distribution['rebate_one'] = floatval($distribution['rebate_one']);
                $distribution['rebate_two'] = floatval($distribution['rebate_two']);
                $distribution['rebate_three'] = floatval($distribution['rebate_three']);
                $data['distribution_rebate_type'] =$distribution['rebate_type'];
            }
            for ($i=0;$i<$data['member']['distribution_mode'];$i++){
                switch ($i){
                    case 0:
                        if($distribution['rebate_one']>0){
                            array_push($distribution_list,$distribution['rebate_one'].$suffix);
                        }
                        break;
                    case 1:
                        if($distribution['rebate_one']>0) {
                            array_push($distribution_list, $distribution['rebate_two'] . $suffix);
                        }
                        break;
                    case 2:
                        if($distribution['rebate_one']>0) {
                            array_push($distribution_list, $distribution['rebate_three'] . $suffix);
                        }
                        break;
                }
            }
        }
        $data['distribution_list'] =$distribution_list;
        //移动端地址
        $sysSetting = SystemSettingService::info('member_website,tblm_is_open');
        $data['member_website'] =isset($sysSetting['member_website'])?$sysSetting['member_website']:'';
        $data['tblm_is_open'] =isset($sysSetting['tblm_is_open'])?$sysSetting['tblm_is_open']:0;
        return success($data);
    }
}
